package com.ygy.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ygy.entity.Favorites;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ygy.entity.Products;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.awt.print.Pageable;
import java.util.List;

/**
 * <p>
 * 收藏表 Mapper 接口
 * </p>
 *
 * @author Ye
 * @since 2024-03-14
 */
@Mapper
public interface FavoritesMapper extends BaseMapper<Favorites> {

    //查询单个用户收藏
    /*List<Products> selectFavoriteProductsByUserId(int user_id);*/

    // 分页查询用户收藏的商品列表
    @Select("SELECT p.* FROM products p " +
            "JOIN favorites f ON p.product_id = f.product_id " +
            "WHERE f.user_id = #{userId} " +
            "LIMIT #{offset}, #{pageSize}")
    List<Products> selectFavoriteProductsByUserId(@Param("userId") int userId, @Param("offset") long offset, @Param("pageSize") int pageSize);

    // 定义新的方法来获取喜欢的产品总数
    @Select("SELECT COUNT(*) FROM products p " +
            "JOIN favorites f ON p.product_id = f.product_id " +
            "WHERE f.user_id = #{userId}")
    int selectFavoriteProductsCountByUserId(@Param("userId") int userId);
}
